/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				TIMERS COUNTERS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
#define SAL_CONFD		DDRD		//Configuracion puerto d OC1B(4), OC1A(5), OC2(7)			//Atmega16
//#define SAL_CONFD		DDRB		//Configuracion puerto d OC1B(4), OC1A(5), OC2(7)			//Atmega8
#define SAL_CONFB		DDRB		//Configuracion puerto b OC0(3)								//Atmega16
#define SAL_OC1B		4			//atmega16																	//atmega16																		//atmega8
#define SAL_OC1A		5			//atmega16
#define SAL_OC0			3			//atmega16
#define SAL_OC2			7			//atmega16
/*-----------------------*/
unsigned long OVERF_TIMER0;			//variable para contar los overflows timer0
unsigned long OVERF_TIMER1;			//variable para contar los overflows timer1
unsigned long CUENTA_TIMER1=0;					//variable para conteo timer 1
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
void OCR1A_conf(void)
{
	SAL_CONFD|=(1<<SAL_OC1A);																//Salidas PWM configuradas puerto D
	TCCR1A|=(1<<COM1A1)|(0<<COM1A0)|(1<<WGM11)|(1<<WGM10);									//PWM, Phase Correct,10-bit OC1A
	TCCR1B|=(0<<WGM13)|(0<<WGM12)|(0<<CS12)|(1<<CS10);										//clkI/O/1024 (From prescaler)
}
void OCR1B_conf(void)
{
	SAL_CONFD|=(1<<SAL_OC1B);																//Salidas PWM configuradas puerto D
	TCCR1A|=(1<<COM1B1)|(0<<COM1B0)|(1<<WGM11)|(1<<WGM10);									//PWM, Phase Correct,10-bit OC1B
	TCCR1B|=(0<<WGM13)|(0<<WGM12)|(0<<CS12)|(1<<CS10);										//clkI/O/1024 (From prescaler)
}
void OCR0_conf(void)		//no para atmega8
{
	SAL_CONFB|=(1<<SAL_OC0);																//Salidas PWM configuradas puerto B	
	TCCR0|=(1<<COM01)|(0<<COM00)|(1<<WGM01)|(1<<WGM00)|(1<<CS02)|(0<<CS01)|(1<<CS00);		//PWM, Phase Correct,8-bit OC0,clkI/O/1024 (From prescaler)
}
void OCR2_conf(void)
{
	SAL_CONFD|=(1<<SAL_OC2);																//Salidas PWM configuradas puerto D
	TCCR2|=(1<<COM21)|(0<<COM20)|(1<<WGM21)|(1<<WGM20)|(1<<CS22)|(1<<CS21)|(1<<CS20);		//PWM, Phase Correct,8-bit OC2,clkI/O/1024 (From prescaler)
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		TIMER 0		
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

			   CS02-CS00 Description
				0 0 0 No clock source (Timer/Counter stopped).
				0 0 1 clkI/O/(No prescaling)
				0 1 0 clkI/O/8 (From prescaler)
				0 1 1 clkI/O/64 (From prescaler)
				1 0 0 clkI/O/256 (From prescaler)
				1 0 1 clkI/O/1024 (From prescaler)
				1 1 0 External clock source on T0 pin. Clock on falling edge.
				1 1 1 External clock source on T0 pin. Clock on rising edge.

				ISR(TIMER0_OVF_vect)---------------->interrupcion
*/
void T0_disable(void)
{
		TCCR0=0;								//reiniciar timer0	
}
void T0_conf_TIMER(void)
{
 		TIMSK|=(1<<TOIE0);						//Enable Overflow Interrupt
		TCCR0|=(1<<CS00);						//clkI/O/(No prescaling)
}
void T0_conf_COUNTER(void)
{
 		TIMSK|=(1<<TOIE0);						//Enable Overflow Interrupt
		TCCR0|=(1<<CS02)|(1<<CS01);				//timer 0 falling edge.
}
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		TIMER 1		
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

			   CS12-CS10 Description
				0 0 0 No clock source (Timer/Counter stopped).
				0 0 1 clkI/O/1 (No prescaling)
				0 1 0 clkI/O/8 (From prescaler)
				0 1 1 clkI/O/64 (From prescaler)
				1 0 0 clkI/O/256 (From prescaler)
				1 0 1 clkI/O/1024 (From prescaler)
				1 1 0 External clock source on T1 pin. Clock on falling edge.
				1 1 1 External clock source on T1 pin. Clock on rising edge.
				
				ISR(TIMER1_OVF_vect)-------------->interrupcion
*/
void T1_conf_COUNTER(void)
{
		TIMSK|=(1<<TOIE1);						//Enable Overflow Interrupt
		TCCR1B|=(1<<CS12)|(1<<CS11);			//timer 1 como Falling
}
void T1_disable(void)
{
		TCCR1B=0;								//reiniciar timer0	
}
